package com.sh.test;

import com.sh.promise.IPromise;
import com.sh.promise.Promise;

import java.util.concurrent.ExecutorService;

/**
 * @Date 13:32 2023/3/9
 **/
public class Demo03 {
    public static void main(String[] args) {
        ExecutorService fixedPool = Promise.pool(1);
        IPromise promise1 = new Promise.Builder().pool(fixedPool).promiseHandler(executor->3).build();
        new Promise.Builder().pool(fixedPool).promise(promise1).promiseHandler(executor->
                {
                    //return 4+(Integer) executor.getPromiseInput();
                    throw new RuntimeException("出错了");
                }).build()
                .then(resolvedData->{
                    System.out.println(resolvedData);
                    return resolvedData;
                }, Throwable::getMessage)
                .addListener((resolvedData, e) -> {
                    //System.out.println(resolvedData);
                    System.out.println("e = " + e.getMessage());
                });
        fixedPool.shutdown();
    }
}
